package com.gaoqian.chatroom.util;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class DButil {
    private static final DataSource datasource ;

    static{
        MysqlDataSource mysqlDataSource=new MysqlDataSource();
        //由于本机是标准端口3306，所以可以省略ip+port
        mysqlDataSource.setUrl("jdbc:mysql:///chatroom?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai");
        mysqlDataSource.setUser("root");
        mysqlDataSource.setPassword("123456");
        datasource=mysqlDataSource;
    }
    public static Connection connection() throws SQLException {
        return datasource.getConnection();
    }
}
